package com.ProtocalAndUdp;

import java.util.HashMap;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.ContextWrapper;
import android.telephony.CellIdentityGsm;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
import android.telephony.CellSignalStrengthGsm;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;

public class PhoneEnvironment {

	/**
	 * @param args
	 */
	public static int[] getLacAndCellId(ContextWrapper context) {

		TelephonyManager mTelephonyManager = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		// 中国移动和中国联通获取LAC、CID的方式
		GsmCellLocation location = (GsmCellLocation) mTelephonyManager
				.getCellLocation();
		int[] values = new int[2];
		if (location == null)
			return null;
		int lac = location.getLac();
		values[0] = lac;
		int cellId = location.getCid();
		values[1] = cellId;

		return values;
	}

	@SuppressLint("NewApi")
	public static HashMap<String, String> getNeigborCells(ContextWrapper context) {
		HashMap<String, String> map = new HashMap<String, String>();
		TelephonyManager mTelephonyManager = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		int i = 1;
		List<CellInfo> cellInfos = (List<CellInfo>) mTelephonyManager
				.getAllCellInfo();
		if(cellInfos!=null){
			for (CellInfo cellInfo : cellInfos) {
				CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
				CellIdentityGsm cellIdentity = cellInfoGsm.getCellIdentity();
				int cId = cellIdentity.getCid();
				map.put("cell" + i, String.valueOf(cId));
				i++;
			}
			
		}
		return map;
	}

}
